package com.solution.admin.order.controller;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.solution.common.constants.PublicStatus.SysCode;
import com.solution.common.controller.BaseController;
import com.solution.common.entity.BaseReturn;
import com.solution.common.page.JSONGrid;
import com.solution.common.page.PageBean;
import com.solution.common.page.PageParam;
import com.solution.pc.order.entity.OrderEvaluationEntity;
import com.solution.pc.order.service.OrderEvaluationService;

/**
 * 订单商品评价web控制层
 * @author xkl
 * @date 2017-12-13 15:32:32
 */
@RequestMapping("/orderEvaluation")
@Controller
public class OrderEvaluationController extends BaseController {

	private Logger logger = LoggerFactory.getLogger(OrderEvaluationController.class);

	@Autowired
	private OrderEvaluationService orderEvaluationService;
	
	/**
	 * 跳转订单商品评价查询页面
	 * @param OrderEvaluation 接收界面查询条件参数
	 * @param request 请求对象
	 * @return 返回对应的页面视图
	 * @author xkl
 	 * @date 2017-12-13 15:32:32
	 */
	@RequestMapping("/toListOrderEvaluationPage")
	public String toListOrderEvaluationPage(OrderEvaluationEntity orderEvaluation, HttpServletRequest request) {
		return "order/orderEvaluation_list";
	}

	/**
	 * 分页查询订单商品评价列表
	 * @param orderEvaluation 接收界面查询条件参数
	 * @param request 请求对象
	 * @return 返回对应的页面视图
	 * @author xkl
 	 * @date 2017-12-13 15:32:32
	 */
	@RequestMapping("/listOrderEvaluationPage")
	@ResponseBody
	public JSONGrid listOrderEvaluationPage(OrderEvaluationEntity orderEvaluation, HttpServletRequest request){
		int pageNum=Integer.parseInt(request.getParameter("page").toString());
		int numPerPage=Integer.parseInt(request.getParameter("rows").toString());
		PageParam pageParam = super.getPageParam(request);
		pageParam.setPageNum(pageNum);
		pageParam.setNumPerPage(numPerPage);
		
		Map<String, Object> paramMap = new HashMap<String, Object>();
		paramMap.put("orderCode", request.getParameter("orderCode"));
		paramMap.put("productCode", request.getParameter("productCode"));
		paramMap.put("productName", request.getParameter("productName"));
		paramMap.put("score", request.getParameter("score"));
		paramMap.put("content", request.getParameter("content"));
		paramMap.put("userName", request.getParameter("userName"));
		paramMap.put("channel", request.getParameter("channel"));
		paramMap.put("isDelete", 1);
		try {
			PageBean pageBean = orderEvaluationService.listOrderEvaluationGroupPage(pageParam, paramMap);
			return new JSONGrid(pageBean.getRecordList(),pageBean.getTotalCount());
		} catch (Exception e) {
			handleException("分页查询订单商品评价失败", logger, e);
		}
		return new JSONGrid();
	}

	/**
	 * 删除订单删商品评论
	 * @param request
	 * @return
	 * @author xkl
	 * @date 2017年12月14日 上午10:35:47
	 */
	@RequestMapping("/doDelEvaluation")
	@ResponseBody
	public BaseReturn doDelEvaluation(HttpServletRequest request){
		Long id = Long.parseLong(request.getParameter("id"));
		BaseReturn result = new BaseReturn();
		try {
			orderEvaluationService.deleteOrderEvaluationById(id);
			result.setCode(SysCode.SUCCESS);
			result.setMsg("删除成功！");
			return result;
		} catch (Exception e) {
			result.setCode(SysCode.ERROR);
			result.setMsg("删除失败！");
			handleException("删除订单商品评价失败", logger, e);
			return result;
		}
	}
	
}
